/*
* @Author: wangliang
* @Date: 2018/4/11
* @description: LP信息
*/
<template>
    <div>
        <el-row class="custom-title m-t-20 m-b-20">
            <h3>LP基本信息
                <span class="m-l-20">最后更新时间：{{modifyTime | cmsMoment}}</span>
                <el-button type="primary" size="mini" round class="m-l-20" @click="save(true)">保存</el-button>
            </h3>
        </el-row>
        <el-form class="custom-box p-20" :model="comLP" :rules="rules" ref="lpForm">
            <el-row>
                <el-col :span="11">
                    <el-form-item label="LP类型" label-width="120px" prop="lpType">
                        <el-select v-model="comLP.lpType" placeholder="请选择" @change='lpChange'>
                            <el-option
                            v-for="(item, index) in dropDown.lpType"
                            :key="index"
                            :label="item.dictName"
                            :value="Number(item.dictValue)">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="资本来源" label-width="120px" prop="source">
                        <el-select v-model="comLP.source" placeholder="请选择" @change='sourceChange'>
                            <el-option
                            v-for="(item, index) in dropDown.capitalFromType"
                            :key="index"
                            :label="item.dictName"
                            :value="Number(item.dictValue)">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>    
        </el-form>
        <div v-if="showOther">
            <ExecutiveInfo
            :type="4"
            :itemId="id"
            :itemType="4"
            class="m-t-20"
            />
            <InvestmentFund></InvestmentFund>
        </div>
        
    </div>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component, Watch } from 'vue-property-decorator';
import ExecutiveInfo from '../../../../../components/management-team/index.vue';
import InvestmentFund from './investment-fund.vue';
import { ComLPDto } from '../../../../../api/Interface';
import LPService from '../../../../../service/subject/company/lp-info/index';
@Component({
  components: {
      ExecutiveInfo, // 高管信息
      InvestmentFund, // 投资基金
  }
})
export default class BasicInfo extends Vue {
    // 初始化数据 相当于data
    // public msg: number = 123;
    public comLP: ComLPDto = {} as ComLPDto; // <PersonVo> {}
    public tabIndex: number = 0;
    public showOther: boolean = false;
    public modifyTime: number = (new Date()).valueOf();
    public id: number = 0;
    public checkList: string[] = [];
    public dropDown: object = {
        capitalFromType: this.$store.state.user.dictionary.dicList.capitalFromType, // 资本来源
        lpType: this.$store.state.user.dictionary.dicList.lpType, // lp类型
    };
    public rules = {
        lpType: [
            { required: true, message: '请选择LP类型', trigger: 'change' }
        ],
        source: [
            { required: true, message: '请选择资本来源', trigger: 'change' },
        ],
    };
    public disabledList: boolean[] = [];
    // refs
    public $refs: {
        lpForm: HTMLFormElement
    };

    // watch
    @Watch('msg')
    public onChildChanged(val: string, oldVal: string) {
        return val + '***';
    }

    // 声明周期钩子
    public mounted() {
        // this.getLPInfo();
    }

    // 方法
    // 保存
    public async save(showBool: boolean) {
        this.$refs.lpForm.validate( async ( valid: boolean) => {
            if (valid) {
                if (this.id === 0 || this.id === null) { // 添加
                    this.comLP.companyId = Number(this.$route.params.itemId);
                    const res = await LPService.saveComLP(this.comLP);
                    if (res.resCode === '0') {
                        if (showBool) {
                            this.$message.success('添加成功');
                        }
                        this.getLPInfo();
                    }
                } else {
                    this.comLP.companyId = Number(this.$route.params.itemId);
                    this.comLP.id = this.id;
                    const res = await LPService.updateComLP(this.comLP);
                    if (res.resCode === '0') {
                        if (showBool) {
                            this.$message.success('修改成功');
                        }
                        this.getLPInfo();
                    }
                }
            } else {
                this.$message.error('请完善信息');
            }
        });
    }
    // 获取lp信息
    public async getLPInfo() {
       const res = await LPService.getComLP({companyId: Number(this.$route.params.itemId)});
        if (res.resCode === '0') {
            this.comLP = res.data;
            this.id = res.data.id;
            this.modifyTime = res.data.modifyTime;
            if (this.id === null) {
                this.showOther = false;
            }
            if (this.id !== 0 && this.id !== null) {
                this.showOther = true;
            }
            // 控制tab
            if (!res.data.lpType || !res.data.source) {
                this.$emit('lpTest', false);
            } else {
                this.$emit('lpTest', true);
            }
            res.data.lpType ? this.disabledList[0] = true : this.disabledList[0] = false; // lp
            res.data.source ? this.disabledList[1] = true : this.disabledList[1] = false; // 来源
            this.testNotice();
        } 
    }
    // lp
    public lpChange() {
        if (this.comLP.lpType) {
            this.disabledList[0] = true;
        } else {
            this.disabledList[0] = false;
        }
        this.testNotice();
    }
    // 来源
    public sourceChange() {
        if (this.comLP.source) {
            this.disabledList[1] = true;
        } else {
            this.disabledList[1] = false;
        }
        this.testNotice();
    }
    // 验证通知
    public testNotice() {
        if (this.disabledList.indexOf(false) >= 0) {
            this.$emit('lpTest', false);
        } else {
            this.$emit('lpTest', true);
        }
    }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.ca-title {
    height: 36px;
    overflow: hidden;
}
.ca-title h3{
    font-weight: normal;
    font-size: 18px;
    color: #333333;
    float: left;
}
.line-h {
    line-height: 36px;
}
.addBtn {
    font-size: 14px;
    margin-top: 12px;
}
.el-checkbox+.el-checkbox {
    margin-right: 10px;
}
.el-checkbox {
    color: #606266;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    margin-left: 10px;
}
</style>